package com.exonline.backstage.controller.serverinfo;

import com.exonline.backstage.entity.OnlineInfo;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/info")
public class InfoServlet extends HttpServlet {
    ObjectMapper mapper = new ObjectMapper();
    OnlineInfoService service = new OnlineInfoService();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if(method!=null){
           if(method.equals("onlineinfo")){
               getOnlineInfo(req, resp);
               mapper.writeValue(resp.getWriter(),new OnlineInfo());
           }
        }
    }

    private  void getOnlineInfo(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        OnlineInfo onlineInfo = service.getOnlineInfo(req);
      mapper.writeValue(resp.getWriter(),onlineInfo);
    }
}
